package com.atguigu.admin.controller;


import com.atguigu.admin.model.entity.SysOperLog;
import com.atguigu.admin.model.vo.SysOperLogQueryVo;
import com.atguigu.admin.service.SysOperLogService;
import com.atguigu.common.result.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 操作日志记录 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2022-10-29
 */
@Api(tags = "操作日志")
@RestController
@RequestMapping("/admin/sysOperLog")
@CrossOrigin
public class SysOperLogController {
    @Autowired
    private SysOperLogService sysOperLogService;


    @ApiOperation(value = "获取分页列表")
    @GetMapping("/v1/{page}/{limit}")
    public Result index(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Long page,

            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Long limit,

            @ApiParam(name = "sysOperLogQueryVo", value = "查询对象", required = false)
                    SysOperLogQueryVo sysOperLogQueryVo) {
        IPage<SysOperLog> pageModel = sysOperLogService.selectPage(page, limit, sysOperLogQueryVo);
        return Result.ok(pageModel);
    }


    @ApiOperation(value = "删除日志")
    @DeleteMapping("/v1/remove/{id}")
    public Result remove(@PathVariable Long id) {
        sysOperLogService.removeById(id);
        return Result.ok();
    }
}

